<template>
    <div class="qingwu">
        <div class="admin_table_page_title">
            <a-button @click="$router.back()" class="float_right" icon="arrow-left">返回</a-button>
            反馈分类编辑
        </div>
        <div class="unline underm"></div>
        <div class="admin_form">
            <a-form-model :label-col="{ span: 3 }" :wrapper-col="{ span: 18 }">
                <a-form-model-item label="名称">
                    <a-input v-model="info.name"></a-input>
                </a-form-model-item>
                <a-form-model-item label="排序">
                    <a-input v-model="info.sort"></a-input>
                </a-form-model-item>

                <a-form-model-item label="是否启用">
                    <a-radio-group name="is_show" :value="info.is_show" @change="showChange">
                        <a-radio :value="1">是</a-radio>
                        <a-radio :value="0">否</a-radio>
                    </a-radio-group>
                </a-form-model-item>

                <a-form-model-item :wrapper-col="{ span: 12, offset: 5 }">
                    <a-button type="primary" @click="handleSubmit">提交</a-button>
                </a-form-model-item>
            </a-form-model>
        </div>
    </div>
</template>

<script>
import moment from "moment";

export default {
    components: {},
    props: {},
    data() {
        return {
            info: {
                is_show: 1,
                sort: 0,
                name: ''
            },
            id: 0,
            loading: false,
        };
    },
    watch: {},
    computed: {},
    methods: {
        moment,
        handleSubmit() {
            // 验证代码处
            if (this.$isEmpty(this.info.name)) {
                return this.$message.error("名称不能为空");
            }

            let api = this.$apiHandle(this.$api.RefundCate, this.id);
            if (api.status) {
                this.$put(api.url, this.info).then((res) => {
                    if (res.code == 200) {
                        this.$message.success(res.msg);
                        return this.$router.back();
                    } else {
                        return this.$message.error(res.msg);
                    }
                });
            } else {
                this.$post(api.url, this.info).then((res) => {
                    if (res.code == 200) {
                        this.$message.success(res.msg);
                        return this.$router.back();
                    } else {
                        return this.$message.error(res.msg);
                    }
                });
            }
        },
        get_info() {
            this.$get(this.$api.RefundCate + "/" + this.id).then((res) => {
                this.info = res.data;
            });
        },
        // 获取菜单列表
        onload() {
            // 判断你是否是编辑
            if (!this.$isEmpty(this.$route.params.id)) {
                this.id = this.$route.params.id;
                this.get_info();
            }
        },
        showChange(e) {
            this.info.is_show = e.target.value;
        },
    },
    created() {
        this.onload();
    },
    mounted() {
    },
};
</script>
<style lang="scss" scoped>
.permission_title {
    background: #efefef;
    padding: 0 20px;
    box-sizing: border-box;
    border-radius: 4px;
}

.cblock {
    margin-top: 10px;
    margin-bottom: 10px;
}

.cbox {
    width: 33%;
    float: left;
}
</style>
